
# Files
HEADERS = $(wildcard src/*.h)
SRC = $(wildcard src/*.cpp)
OBJ = ${SRC:.cpp=.o}

# Project data
name = dargite3d
version = 1.0.0
EXE = share/dargite3d/${name}

# Compiler arguments
CC = g++
CFLAGS = -Wall -Wextra -pedantic
LIBS = -lglut -lGL -lGLU -lGLEW

### Rules ###

# Executable
${EXE}: ${OBJ}
	$(CC) $(CFLAGS) -o $@ $(OBJ) $(LIBS)

tarball:
	@echo Making tarball ${name}-${version}.tar.gz
	@tar -czf $(name)-$(version).tar.gz bin/* LICENSE Makefile \
		share/* README.md ${SRC} ${HEADERS} --exclude=bin/dargite3d \
		--exclude=${EXE} configure Makefile.in

install: ${EXE}
	@echo Installing project to ${DEST_DIR}@APP_DIR ...
	@mkdir -p ${DEST_DIR}@APP_DIR/share
	@cp -rf share/dargite3d/ ${DEST_DIR}@APP_DIR/share/
	@chmod 755 ${DEST_DIR}@APP_DIR/share/dargite3d/${name}
	@mkdir -p ${DEST_DIR}@APP_DIR/bin
	@cp -f bin/dargite3d ${DEST_DIR}@APP_DIR/bin
	@chmod 755 ${DEST_DIR}@APP_DIR/bin/dargite3d
	@echo Project installed!

uninstall:
	@echo removing executable from @APP_DIR
	@rm -f @APP_DIR/share/dargite3d @APP_DIR/bin/${name}

clean:
	@echo Cleaning ...
	@-rm -f bin/dargite3d ${EXE} $(OBJ) Makefile
	@-rm -f $(name)-$(version).tar.gz 

.PHONY : tarball clean install uninstall

# Re-compile when any header changes
${OBJ}: ${HEADERS}

# How to compile cpp files
.cpp.o:
	${CC} ${CFLAGS} -c -o ${<:.cpp=.o} $< ${LIBS}
